package com.amit.hibernate;

import java.util.Date;

import java.util.HashSet;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab22Clent1 {

	public static void main(String[] args) {
		
		SessionFactory sessionfactory=CHibernateUtil.getfactory();
		Session session=sessionfactory.openSession();
		Transaction tx=session.beginTransaction();
		
		//1.Add customer
		Customer cust1=new Customer("amit", "amit@com", new Date(), new Long(9999));
		session.save(cust1);
		

		Customer cust2=new Customer("anil", "anil@com", new Date(), new Long(9999));
		session.save(cust2);
		
		//2.Add accounts
		
		Account a1=new Account("SA",5000.0);
		session.save(a1);
		

		Account a2=new Account("SA",10000.0);
		session.save(a2);
		

		Account a3=new Account("SA",150000.0);
		session.save(a3);
		

		 Set<Account> accs=new HashSet<Account>();
		 accs.add(a1);
		 accs.add(a2);
		 accs.add(a3);
		 
		 cust1.setAccounts(accs);
		 
		 Set<Account> accs1=new HashSet<Account>();
		 accs1.add(a2);
		 accs1.add(a3);
		 
		 cust2.setAccounts(accs1);
		 

		
		tx.commit();
		session.close();
		
	
	}

}
